package com.steak.elasticsearch.controller;

import com.steak.elasticsearch.entity.Item;
import com.steak.elasticsearch.service.ItemService;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ItemController {

    @Autowired
    private ItemService itemService;

    @GetMapping("/listItem")
    public Iterable<Item> listItem(){
        return itemService.queryAll();
    }

    @GetMapping("/polymerizationQuery")
    public Map<String, Integer> polymerizationQuery() {
        return itemService.polymerizationQuery();
    }

    @GetMapping("/queryByTitle")
    public Map<String,List<Item>> queryByTitle(@RequestParam("title")String title){
       return itemService.queryByTitle(title);
    }

    @GetMapping("/queryByBrand")
    public Map<String,List<Item>> queryByBrand(@RequestParam("brand")String brand){
        return itemService.queryByBrand(brand);
    }
}
